home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17986 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: I don't believe it! Weird thing about Virtual tables
  5. Date: 17 Apr 1996 23:12:26 -0000
  6. Organization: Datalytics, Inc.
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: herbs@connobj.com
  9. Message-ID: <4l3tsq$c08@netlab.cs.rpi.edu>
  10. References: <4ku0ee$hjj@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: Wed, 17 Apr 1996 00:00:21 -0400
  13.  
  14. Rodrigo de Salvo Braz wrote:
  15. [snip]
  16. > The virtual table of one of my classes (say, Dog) is initialized by
  17. > code!
  18. >  It sounds ok at first, but since each module has its own initializing
  19. > code (for global variables and similar stuff), I have Dog's virtual
  20. > table initialized AFTER initializing code of modules located BEFORE
  21. > Dog's module in the Project definition. Since I have variables using
  22. > Dog in those earlier modules, I get a real crash![snip]
  23. > Am doing any mistake on it? Is there any option preventing it? Why
  24. > doesn't the compiler create the virtual tables already initialized?
  25.  
  26. It sounds as though you are using static Dogs.  Since the 
  27. initialization order of statics are not guaranteed, the static 
  28. Dogs used in your other translation units may not be initialized 
  29. by the time you use them.
  30.  
  31. One workaround for this is to declare the static Dogs in the 
  32. function where they're needed, or to declare them in a function 
  33. that can then provide them to the others.
  34.  
  35. -- 
  36. Rob Stewart    | My opinions are generally my own.  They do
  37. Datalytics, Inc.| not necessarily reflect those of my employer.
  38.  
  39.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  40.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  41.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  42.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  43.